package java3_23.Zoo;

import java.util.Scanner;

public class Xbl {

    private Animal[] a;

    public Xbl(){
        Animal[] a = new Animal[30];
        a[0] = new Tiger("小美丽","母","老虎");
        a[1] = new Lion("大黄","母","狮子");
        a[2] = new Lion("二黄","公","狮子");
        a[3] = new Dolphin("欢欢","公","海豚");
        a[4] = new Orangutan("大黑","公","猩猩");
        a[5] = new Wolf("武大狼","公","狼");
        a[6] = new Elephant("晶晶","母","大象");
        a[7] = new Seal("文文","母","海豹");
        a[8] = new Bat("小黑","母","蝙蝠");
        a[9] = new Parrot("阿绿","公","鹦鹉");
        a[10] = new Eagle("阿黑","公","老鹰");

        this.a = a;
    }

    public Xbl(Animal[] a) {
        this.a = a;
    }

    /**
     * 参观
     * @param b 动物名称或者名字
     */
    public void visit(String b){
        for (int i = 0; i < a.length; i++) {
            if (a[i]==null){
                System.out.println("您要参观的动物不存在");
                return;
            }
            if (a[i].getType().equals(b)||a[i].getName().equals(b)){
                a[i].play();
                return;
            }
        }
    }

    public void show(){

        for (int i = 0; i < a.length; i++) {
            if (a[i]==null){
                return;
            }
            System.out.println("这里有"+a[i].getType()+a[i].getName());
        }
    }

    public static void main(String[] args){

        Scanner scanner = new Scanner(System.in);
        System.out.println("欢迎光临肥东县人民动物园!");
        while (true){
            System.out.println("1.查看动物"+"\t"+"2.喂食" +"\t"+"3.参观"+"\t"+"4.回家");
            int x = scanner.nextInt();
            switch (x){
                case 1:{
                    Xbl t = new Xbl();
                    t.show();
                    break;
                }
                case 2:{
                    System.out.println("喂哪种动物:");
                    String b = scanner.next();
                    Xbl t = new Xbl();
                    t.feed(b);
                    break;
                }
                case 3:{
                    System.out.println("参观哪种动物:");
                    String c = scanner.next();
                    Xbl t = new Xbl();
                    t.visit(c);
                    break;
                }
                case 4:{
                    return;
                }
            }
        }
    }

    private void feed(String b) {
        for (int i = 0; i < a.length; i++) {
            if (a[i]==null){
                System.out.println("您要投喂的动物不存在");
                return;
            }
            if (a[i].getType().equals(b)||a[i].getName().equals(b)){
                a[i].eat();
                return;
            }
        }
    }

}
